package com.make.sunflower.common;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

@Data
@Builder
@AllArgsConstructor
public class Result<T> implements Serializable {

    private static final long serialVersionUID = -1060126915593634578L;

    public static final String SUCCESS_MSG__DEFAULT = "请求处理成功!";
    public static final String FAIL_MSG__DEFAULT = "请求处理失败!";
    public static final String SUCCESS_CODE_DEFAULT = "202";
    public static final String FAIL_CODE_DEFAULT = "500";

    private String msg;
    private String code;
    private T data;

    public Result() {
        msg = SUCCESS_MSG__DEFAULT;
        code = SUCCESS_CODE_DEFAULT;
    }

    public static  <T> Result success(T data){
        return new Result(SUCCESS_MSG__DEFAULT, SUCCESS_CODE_DEFAULT, data);
    }

    public static  <T> Result fail(T data){
        return fail(FAIL_MSG__DEFAULT, FAIL_CODE_DEFAULT, data);
    }

    public static <T> Result fail(String msg,String code,T data) {
        return new Result(msg, code, data);
    }
}
